package com.ym.controller.soso;

import com.github.pagehelper.PageInfo;
import com.ym.common.constant.Constants;
import com.ym.common.utils.HtmlHandleUtil;
import com.ym.common.utils.StringUtil;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.soso.domain.param.PensionInfoAppQryParam;
import com.ym.soso.domain.vo.PensionInfoSimVO;
import com.ym.soso.enums.SpecServiceEnum;
import com.ym.soso.service.IPensionInfoSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author wenbo
 * @Date 2019/12/13 11:49
 **/


@Api(tags = "APP-手机端养老相关")
@RestController
@RequestMapping(value = "/soso/pension", headers = Constants.Api.VERSION)
@Validated
public class PensionController extends BaseController {

	@Autowired
	private IPensionInfoSV pensionInfoSV;

	@Log(dataBase = true, printBody = false)
	@ApiOperation("养老列表")
	@GetMapping("/list")
	@ResponseBody
	public APIResponse<PageInfo<PensionInfoSimVO>> listPagePensionInfo(
			@ApiParam(name = "pharmacyInfo", value = "养老查询条件", required = true)
					PensionInfoAppQryParam pensionInfoAppQryParam) {
		PageDomain.startPage();
		int[] specServices = pensionInfoAppQryParam.getSpecServices();
		if (specServices != null && specServices.length == 6) {
			String join = StringUtil.join("", specServices);
			String keys = SpecServiceEnum.getKeys(join);
			if(!"00".equals(keys)){
				pensionInfoAppQryParam.setSpecServicesStr(keys);
			}
		}
		List<PensionInfoSimVO> pensionInfos = pensionInfoSV.listPensionInfo(pensionInfoAppQryParam);
		return successPage(pensionInfos);
	}

	@Log(dataBase = true, printBody = false)
	@ApiOperation("养老详情")
	@GetMapping("/detail")
	@ResponseBody
	public APIResponse<PensionInfoSimVO> getPensionInfoDetail(
			@ApiParam(name = "id", value = "养老主键", required = true)
			@RequestParam Long id,
			@RequestParam(defaultValue = "0") int width
	) {
		PensionInfoAppQryParam qryParam = new PensionInfoAppQryParam();
		Long[] longs = new Long[]{id};
		qryParam.setIds(longs);
		List<PensionInfoSimVO> pensionInfos = pensionInfoSV.listPensionInfo(qryParam);
		if (pensionInfos.isEmpty()) {
			return successData(null);
		}
		PensionInfoSimVO pensionInfoSimVO = pensionInfos.get(0);
		pensionInfoSimVO.setIntroduction(HtmlHandleUtil.resize(pensionInfoSimVO.getIntroduction(), width));
		pensionInfoSimVO.setServiceItem(HtmlHandleUtil.resize(pensionInfoSimVO.getServiceItem(), width));
		pensionInfoSimVO.setRates(HtmlHandleUtil.resize(pensionInfoSimVO.getRates(), width));
        pensionInfoSimVO.setFacility(HtmlHandleUtil.resize(pensionInfoSimVO.getFacility(), width));
        pensionInfoSimVO.setRoomNotes(HtmlHandleUtil.resize(pensionInfoSimVO.getRoomNotes(), width));
        return successData(pensionInfoSimVO);
	}

}
